package com.springbootblog.dao.sqlBuilder;

import com.springbootblog.pojo.Message;

import java.util.Map;

public class MessageSqlBuilder
{
    public String getMessageList(Map<String, Object> param)
    {
        String sql = "SELECT p1.*,p2.nickname,p2.figureurl_qq,p2.figureurl_wx from message p1 " +
                "LEFT JOIN user p2 on p1.uid = p2.id " +
                "where p1.replyid = 0 AND p1.status = 0 " +
                "order by p1.addtime DESC";
        return sql;
    }

    public String getMessageListTwo(Map<String, Object> param)
    {
        String sql = "SELECT p1.*,p2.nickname,p2.figureurl_qq,p2.figureurl_wx from message p1 " +
                "LEFT JOIN user p2 on p1.uid = p2.id " +
                "where returnid = '" + param.get("id") + "' AND status = 0 order by addtime asc ";
        return sql;
    }

    public String getMessageListTwoReply(Map<String, Object> param)
    {
        String sql = "SELECT p1.*,p2.nickname,p2.figureurl_qq,p2.figureurl_wx from message p1 " +
                "LEFT JOIN user p2 on p1.uid = p2.id " +
                "where p1.id = '"+param.get("id")+"' AND status = 0 limit 1 ";
        return sql;
    }

    public String updateUserInfo(Map<String, Object> param)
    {
        String sql = "UPDATE user SET email = '"+param.get("param2")+"' WHERE id = '"+param.get("param1")+"'";
        return sql;
    }

    public String getMessageInfo(Map<String, Object> param)
    {
        String sql = "SELECT * FROM message WHERE id = '"+param.get("id")+"' ";
        return sql;
    }

    public String getUserInfoById(Map<String, Object> param)
    {
        String sql = "SELECT * FROM user WHERE id = '"+param.get("id")+"' ";
        return sql;
    }

    public String addMessageData(Message message)
    {
        String sql = "INSERT INTO message(uid,content,addtime,replyid,returnid) VALUES ('"+message.getUid()+"','"+message.getContent()+"',NOW(),'"+message.getReplyid()+"','"+message.getReturnid()+"')";
        return sql;
    }


}
